<div class="fsh-pop">
    <div id="add_form" class="layui-form" lay-filter="example">
        <input type="hidden" name="user_id" id="role_id" value="<%=user_id%>"/>
        <input type="hidden" id="sex_hidden" value="<%=sex%>"/>
        <input type="hidden" value="<%=type%>" id="defaultType"/>
        <div class="layui-form-item">
            <label class="layui-form-label"><i>*</i>用户类型</label>
            <div class="layui-input-block">
                <input type="hidden" name="role_id" id="roleId" value="<%=role_id%>"/>
                <select id="type" lay-filter="type" name="type">
                    <option value="1">管理员</option>
                    <option value="2">平台老师</option>
                    <option value="3">学校老师</option>
                    <option value="4">学生</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label"><i>*</i>姓名</label>
            <div class="layui-input-block">
                <input name="nickname" maxlength="20" lay-verify="required"
                       value="<%=nickname%>" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><i>*</i>性别</label>
            <div class="layui-input-block">
                <input type="radio" name="sex" value="0" title="男" id="sex_man">
                <input type="radio" name="sex" value="1" title="女" id="sex_women">
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label"><i>*</i>电话</label>
            <div class="layui-input-block">
                <input name="phone" maxlength="20" value="<%=phone%>" class="layui-input" lay-verify="phone|required">
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label"><i>*</i>邮箱</label>
            <div class="layui-input-block">
                <input name="email" maxlength="20" value="<%=email%>" class="layui-input" lay-verify="email">
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">头像</label>
            <div class="layui-input-block">
                <div class="layui-upload">
                    <button type="button" class="layui-btn" id="upload_header">上传头像</button>
                    <div class="layui-upload-list">
                        <img class="layui-upload-img" id="demo1" src="<%=photo%>">
                        <p id="demoText"></p>
                        <input type="hidden" name="photo" id="photo" value="<%=photo%>">
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<style type="text/css">
    #demo1 {
        width: 100px;
        height: 100px;
        border: 1px solid #e3e3e3;
    }
</style>
<script type="text/javascript">
    if ($("#sex_hidden").val() == 1) {
        $("#sex_women").attr('checked', true);
    } else {
        $("#sex_man").attr('checked', true);
    }

    layui.use(['form', 'upload'], function () {
        var form = layui.form;
        var upload = layui.upload;
        $('#type').val($('#defaultType').val());//默认用户类型
        form.on('select(type)', function (data) {
            $('#roleId').val(data.elem[data.elem.selectedIndex].val);

        });

        // 上传图片
        upload.render({
            elem: '#upload_header'
            , url: context + '/api/fileupload/add'
            , field: 'attach'
            , done: function (res) {
                if (res.success) {
                    $('#demo1').attr('src', res.link);
                    $('#photo').val(res.link);
                } else {
                    layui.layer.msg('上传失败');
                }
                //上传成功
            }
        });

    });


</script>
